package com.ding.eduservice.controller;


import com.ding.commonutils.Result;
import com.ding.eduservice.entity.EduChapter;
import com.ding.eduservice.entity.chapter.ChapterVo;
import com.ding.eduservice.service.EduChapterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 课程 前端控制器
 * </p>
 *
 * @author testjava
 * @since 2020-11-16
 */
@RestController
@RequestMapping("/eduservice/chapter")
@CrossOrigin
public class EduChapterController {
    @Autowired
    private EduChapterService eduChapterService;

    //课程大纲列表，根据课程id进行查询
    @GetMapping("getChapterVideo/{courseId}")
    public Result getChapter(@PathVariable String courseId){
        List<ChapterVo> list = eduChapterService.getChapterByCourseId(courseId);
        return Result.ok().data("allchapterVideo",list);
    }

    //添加章节
    @PostMapping("addChapteradd")
    public Result addChapter(@RequestBody EduChapter eduChapter){
        int add = eduChapterService.addChapterdata(eduChapter);
        if(add>0){
            return Result.ok();
        }else {
            return Result.error();
        }
    }

    //根据章节id查询章节
    @GetMapping("getInfo/{chapterId}")
    public  Result getInfo(@PathVariable String chapterId){
        EduChapter eduChapter =  eduChapterService.getInfo(chapterId);
        return Result.ok().data("chapter",eduChapter);
    }

    //修改章节
    @PostMapping("updatechapter")
    public Result updateChapter(@RequestBody EduChapter eduChapter){
         eduChapterService.updateChapterdata(eduChapter);
            return Result.ok();

    }

    @DeleteMapping("delchapter/{chaptedId}")
    public Result delChapter(@PathVariable String chaptedId){
        int del = eduChapterService.delChapterdata(chaptedId);
        if(del>0){
            return Result.ok();
        }else {
            return Result.error();
        }
    }


}

